package com.boding.power.controller;

import com.boding.power.common.Constants;
import com.boding.power.dto.BusinessinfoDto;
import com.boding.power.dto.CustomerDto;
import com.boding.power.dto.VipinfoDto;
import com.boding.power.model.Businessinfo;
import com.boding.power.model.Customer;
import com.boding.power.model.Vipinfo;
import com.boding.power.utils.DataGrid;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;

/**
 * 普通用户控制类
 * 
 * @author giegie
 * @date 2016年5月10日
 * @description
 * 
 */
public class PeopleController extends Controller {
	public void listCustomerUI() {
		render("customerList.jsp");
	}

	public void listCustomer() {
		String searchField = getPara("searchField");
		String searchString = getPara("searchString");
		DataGrid<CustomerDto> dataGrid = Customer.dao.findByPage(
				getParaToInt("page"), getParaToInt("rows"), searchField,
				searchString);
		renderJson(dataGrid);
	}
	
	public void operateCustomer(){
		String oper = getPara("oper");
		Customer customer = getModel(Customer.class,"",true);
		if("edit".equals(oper)){
			Customer c = Customer.dao.findById(customer.getId());
			c.setPhone(customer.getPhone());
			c.setName(customer.getName());
			c.update();
		} else if("del".equals(oper)){
			Customer c = Customer.dao.findById(customer.getId());
			c.setDelFlag(Constants.FLAG_DEL);
			c.update();
		}
		renderText("success");
	}
	
	public void listVipInfoUI() {
		render("vipinfoList.jsp");
	}

	public void listVipInfo() {
		String searchField = getPara("searchField");
		String searchString = getPara("searchString");
		DataGrid<VipinfoDto> dataGrid = Vipinfo.dao.findByPage(
				getParaToInt("page"), getParaToInt("rows"), searchField,
				searchString);
		renderJson(dataGrid);
	}
	
	public void operateVipInfo(){
		String oper = getPara("oper");
		Vipinfo vipinfo = getModel(Vipinfo.class,"",true);
		if("edit".equals(oper)){
			Vipinfo v = Vipinfo.dao.findById(vipinfo.getId());
			v.setPhone(vipinfo.getPhone());
			v.setName(vipinfo.getName());
			v.update();
		} else if("del".equals(oper)){
			Vipinfo v = Vipinfo.dao.findById(vipinfo.getId());
			v.setDelFlag(Constants.FLAG_DEL);
			v.update();
		}
		renderText("success");
	}
	
	public void listBusinessInfoUI() {
		render("businessinfoList.jsp");
	}

	public void listBusinessInfo() {
		String searchField = getPara("searchField");
		String searchString = getPara("searchString");
		DataGrid<Record> dataGrid = Businessinfo.dao.findByPage(
				getParaToInt("page"), getParaToInt("rows"), searchField,
				searchString);
		renderJson(dataGrid);
	}
	
	public void operateBusinessInfo(){
		String oper = getPara("oper");
		Businessinfo businessinfo = getModel(Businessinfo.class,"",true);
		if("edit".equals(oper)){
			Businessinfo b = Businessinfo.dao.findById(businessinfo.getId());
			b.setPhone(businessinfo.getPhone());
			b.setName(businessinfo.getName());
			b.update();
		} else if("del".equals(oper)){
			Businessinfo b = Businessinfo.dao.findById(businessinfo.getId());
			b.setDelFlag(Constants.FLAG_DEL);
			b.update();
		}
		renderText("success");
	}
	
	public void listAuthstrUI(){
		render("authstrList.jsp");
	}
	
	public void listAuthstr(){
		String searchField = getPara("searchField");
		String searchString = getPara("searchString");
		DataGrid<Record> dataGrid = Businessinfo.dao.findByAuthstrPage(
				getParaToInt("page"), getParaToInt("rows"), searchField,
				searchString);
		renderJson(dataGrid);
	}
}
